package com.mgface.framework.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.boot.context.embedded.ServletContextInitializer;
import org.springframework.stereotype.Component;


@Component
public class SBDAutowireServlet extends HttpServlet implements ServletContextInitializer {
	private static final Logger log = LogManager.getLogger(SBDAutowireServlet.class);
	/**
	 * 
	 */
	private static final long serialVersionUID = 7081259628695885959L;

	@Override
	public void init(ServletConfig config) throws ServletException {
		super.init(config);
	}

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		resp.setContentType("text/html; charset=UTF-8");
		PrintWriter out = resp.getWriter();
		out.println("");
		out.println("SBDAutowireServlet。。。。");
		out.flush();
		out.close();
	}

	@Override
	public void onStartup(ServletContext servletContext) throws ServletException {
		log.info("[ServletContextInitializer(servletcontext初始化器)]进行加载......");
		servletContext.addServlet("SBDAutowireServlet", SBDAutowireServlet.class).addMapping("/SBDAutowireServlet");
	}
}
